#ifndef TEMPERATURE_MODULE_H
#define TEMPERATURE_MODULE_H

#include <Arduino.h>

#define TAO_PIN A0
#define T_ON_PIN 53

#define TRANSFER_FUNC_LEVEL 3
#define OFS_TEMP 2.0

static float temp = 0.0;

float get_temp(float voltage)
{
#if TRANSFER_FUNC_LEVEL == 2
  return 204.6398 - (7.857932E-6 * voltage * voltage) - (1.777501E-1 * voltage);
#elif TRANSFER_FUNC_LEVEL == 3
  return 205.5894 - (1.809628E-9 * voltage * voltage * voltage) - (3.325395E-6 * voltage * voltage) - (1.814103E-1 * voltage) + OFS_TEMP;
#endif

  return 0.0;
}
void temperature_module_setup()
{
pinMode(T_ON_PIN, OUTPUT);

digitalWrite(T_ON_PIN, 1);
}

void temperature_module_loop()
{
  analogReadResolution(16);
  int val = analogRead(TAO_PIN);
  float voltage = val * 3300 * 1.0 / (1 << 16);
  temp = get_temp(voltage);

}

#endif // TEMPERATURE_MODULE_H